<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page isELIgnored="false"  %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath %>">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<link rel="stylesheet" type="text/css" href="js/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/easyui/themes/icon.css">
	<script type="text/javascript" src="js/easyui/jquery.easyui.min.js"/></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>讨债系统</title>
</head>
<body>
	<!-- fit：让内部布局的大小适应外部布局的大小 -->
	<div class="easyui-layout" data-options="fit:true"> <!-- data-options是easyUI的扩展属性 -->
<!-- 		<div data-options="region:'north',split:true,border:false" style="height:50px"> -->
<!-- 		</div> -->

		<div data-options="region:'center',border:false">
			<div id="wu-toolbar-2">
<!-- 				<a id="add_organ" href="javascript:;" onclick="javascript:$('#dd').dialog('open')" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增</a>  -->
<!-- 				<a id="edit_organ" href="javascript:;" onclick="javascript:$('#dd').dialog('edit')" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>  -->
<!-- 				<a id="remove_organ" href="javascript:;" onclick="javascript:$('#dd').dialog('remove')" class="easyui-linkbutton" data-options="iconCls:'icon-cut'">删除</a>  -->
				<a id="add_organ" href="javascript:;" onclick="openAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增</a> 
				<a id="add_organ" href="javascript:;" onclick="openEdit()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">编辑</a> 
				<a id="add_organ" href="javascript:;" onclick="remove()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">删除</a> 
			</div>
	   		<table id="wu-datagrid-2" class="easyui-treegrid" toolbar="#wu-toolbar-2"></table>
		</div>
		
		<!-- 弹窗 -->
		<div id="wu-dialog-2" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
			<form id="wu-form-2" method="post">
		        <table>
	            <tr>
	                <td width="60" align="right">上级机构:</td>
	                <td><select name="parentId">
	                	<option value="0" selected="selected">中国银行</option>
	                	<option value="1">中国建设银行</option>
	                	<option value="2">中国农业银行</option>
	                </select></td>
	            </tr>
	            <tr>
	                <td width="60" align="right">机构类型:</td>
	                <td><select name="type">
	                	<option value="1" selected="selected">主公司</option>
	                	<option value="2">分公司</option>
	                </select></td>	            
	                </tr>
	            <tr>
	                <td width="60" align="right">负责人:</td>
	                <td><select name="principalId">
	                	<option value="1" selected="selected">张三</option>
	                	<option value="2">李四</option>
	                	<option value="3">王五</option>
	                </select></td>	            
	                </tr>
	            
	            <tr>
	                <td width="60" align="right">机构名称:</td>
	                <td><input type="text" name="name" class="wu-text" /></td>
	            </tr>
	            <tr>
	                <td width="60" align="right">机构编码:</td>
	                <td><input type="text" name="code" class="wu-text" /></td>
	            </tr>
	            <tr>
	                <td width="60" align="right">地址:</td>
	                <td><input type="text" name="address" class="wu-text" /></td>
	            </tr>
	            <tr>
	                <td align="right">电话号码:</td>
	                <td><input type="text" name="phone" class="wu-text" /></td>
	            </tr>
	            <tr>
	                <td align="right">邮政编码:</td>
	                <td><input type="text" name="postCode" class="wu-text" /></td>
	            </tr>
	            <tr>
	                <td align="right">传真号:</td>
	                <td><input type="text" name="fax" class="wu-text" /></td>
	            </tr>
	        </table>
		    </form>
		</div>
		
	</div> 
	
	
	<script type="text/javascript">
	$(function (){
		 list();
	});
	/**
	* 加载当前数据库的数据
	*/
	function list(){
		$('#wu-datagrid-2').treegrid({
		    url:'get_org_list.do',    
			idField:'id', //定义关键字段来标识树节点
			treeField:'name', //定义树节点字段
		//	loadFilter:pagerFilter,	//返回过滤后的数据进行展示	
			rownumbers:true, //如果为true，则显示一个行号列
		//	singleSelect:true,  //如果为true，则只允许选择一行
		//		pageSize:2,    //在设置分页属性的时候初始化页面大小        
		//		pagination:true, //如果为true，则在DataGrid控件底部显示分页工具栏
		//		multiSort:true, //定义是否允许多列排序
			fitColumns:true, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动
			fit:true, //面板大小将自适应父容器
		    columns:[[    
		//	        {field:'id',title:'编号',width:30},    
		        {field:'name',title:'机构名称',width:60},    
		        {field:'type',title:'机构类型',width:60},   
		        {field:'code',title:'机构编码',width:50},   
		        {field:'principalId',title:'负责人',width:50},   
		        {field:'path',title:'业务覆盖区域',width:60},   
		        {field:'address',title:'地址',width:70},   
		        {field:'phone',title:'电话号码',width:70},   
		        {field:'postCode',title:'邮政编码',width:70},   
		        {field:'fax',title:'传真号',width:70},   
		        {field:'createTime',title:'创建时间',width:120,align:'center',
		        	formatter:function(value,row,index){
		        		if (value != null) {
		        			var date = new Date(value);
		        			return date.getFullYear()+'-'+(date.getMonth() + 1)+'-'+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
		        		}
		        	}
		        },  
		        {field:'modifyTime',title:'修改时间',width:120,align:'center',
		        	formatter:function(value,row,index){
		        		var d = new Date(value);
		        		var str = d.toLocaleString();//js日期格式化
		        		return str;
		        	}
		        }
		    ]]    
		});
	}

	/**
	* 点击新增按钮，弹窗出来
	*/
	function openAdd(){
		$('#wu-from-2').form('clear');
		$('#wu-dialog-2').dialog({
			closed: false,
			modal:true,
            title: "新增机构信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler:	 add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-2').dialog('close');                    
                }
            }]
        });
	}
	
	/**
	* 提交新增数据操作
	*/
	function add(){
		$('#wu-form-2').form('submit', {
			url:'add_org.do',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-2').dialog('close');
					var tab = $('#tt').tabs('getSelected');  // 获取选择的面板
					tab.panel('refresh'); //刷新面板
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	*点击编辑按钮，弹窗出来
	*/
	function openEdit(){
		$('#wu-form-2').form('clear');
		var item = $('#wu-datagrid-2').datagrid('getSelected');
		if(item == null || item == ""){
			$.messager.show({
				title:'请选择要修改的信息',
				msg:'消息将在2秒后关闭。',
				showType:'show',
				timeout:2000,
				style:{
					right:'',
					top:document.body.scrollTop+document.documentElement.scrollTop,
					bottom:''
				}
			});
			return;
		}
		var id = item.id;
		
		$.ajax({
			url:'goto_edit_org.do',
			data:{id:id},
			success:function(result){

					$('#wu-form-2').form('load', result)
			}	
		});
		$('#wu-dialog-2').dialog({
			closed: false,
			modal:true,
            title: "修改信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-2').dialog('close');                    
                }
            }]
        });
	}	
	
	/**
	*	修改
	*/
	function edit(){
		var item =$("#wu-datagrid-2").datagrid('getSelected');
		var id = item.id;
		$("#wu-form-2").form('submit',{
			url:'edit_org.do?id='+id,
			success:function(data){
				if (data) {
					$.messager.alert('信息提示','提交成功','info');
					$("#wu-dialog-2").dialog('close');
					var tab = $("#tt").tabs('getSelected');//获取选择的面板
					tab.panel('refresh');
				}else{
					$.messager.alert('信息提示','提交失败','info');
				}
			}
		});
	}
	

	/**
	*点击删除按钮，删除数据
	*/
	function remove(){
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			
			if(result){
				var item = $('#wu-datagrid-2').datagrid('getSelected');
				if(item == null || item == ""){
					$.messager.show({
						title:'请选择要删除的信息',
						msg:'消息将在2秒后关闭。',
						showType:'show',
						timeout:2000,
						style:{
							right:'',
							top:document.body.scrollTop+document.documentElement.scrollTop,
							bottom:''
						}
					});
					return;
				}
				var id = item.id;
// 				var ids = [];
// 				$(items).each(function(){
// 					ids.push(this.productid);	
// 				});
				//alert(ids);return;
				$.ajax({
					url:'remove_org.do',
					data:{id:id},
					success:function(result){
						if(result){
							$.messager.alert('信息提示','删除成功！','info');
							var tab = $('#tt').tabs('getSelected');  // 获取选择的面板
							tab.panel('refresh');
						}
						else
						{
							$.messager.alert('信息提示','删除失败！','info');		
						}
					}	
				});
			}	
		});
	}
	
</script>
</body>
</html>